<!-- 网站信息 -->
<template>
    <div class="website-information">
        <el-form ref="formRef" :rules="rules" class="ls-form" :model="formData" label-width="120px">
            <el-card shadow="never" class="!border-none">
                <div style="display:flex;">
                    <div class="text-xl font-medium mb-[20px]">抖音配置</div>
                    <el-button text  style="background-color:rgba(45, 140, 240, 1);color: white;margin-left:20px;" @click="download">
                        <el-icon><Plus /></el-icon>
                        下载无风险域名文件
                    </el-button>
                    <div style="margin-left:10px;" class="text-xl font-medium">
                        使用抖音自动回复自动撤回功能需配置定时任务
                    </div>
                </div>
                <div style="display:flex;">
                    <div class="text-xl font-medium mb-[20px]">
                        任务链接：{{urling}}/zndl/api/webhook/processRevokeMessages
                        <el-button link  type="primary"  v-copy="urling + '/zndl/api/merchant/processRevokeMessages'">
                            复制
                        </el-button>
                        <el-button link  type="primary"  @click="dialogVisible = true">
                            示例
                        </el-button>
                    </div>
                </div>
                <div class="text-xl font-medium mb-[20px]">抖音配置</div>
                <el-form-item label="独立抖音配置" prop="key">
                    <div class="w-80">
                        <el-switch
                            v-model="formData.douyin_is_open"
                            :active-value="1"
                            :inactive-value="0"
                            class="ml-2"

                        />
                    </div>
                    <el-alert description="开启后使用公共配置，关闭则需填写配置" type="info" :closable="false" />
                </el-form-item>
                <el-form-item label="Client Key:" prop="url" v-if="formData.douyin_is_open == 0">
                    <div class="w-80">
                        <el-input
                            v-model.trim="formData.client_key"
                            placeholder="请输入Client Key"
                            show-word-limit
                        />
                    </div>
                </el-form-item>
                <el-form-item label="Client Secret:" prop="key" v-if="formData.douyin_is_open == 0">
                    <div class="w-80">
                        <el-input
                            v-model.trim="formData.client_secret"
                            placeholder="请输入Client Secret"
                            show-word-limit
                        />
                    </div>
                </el-form-item>
                <el-form-item label="抖音授权回调调试模式" prop="key" v-if="formData.douyin_is_open == 0">
                    <div class="w-80">
                        <el-switch
                            v-model="formData.config_status"
                            :active-value="1"
                            :inactive-value="0"
                            class="ml-2"
                        />
                    </div>
                    <el-alert description="开启后在抖音开放平台配置相关回调地址，配置完需要关闭该开关" type="info" :closable="false" />
                </el-form-item>
            </el-card>
        </el-form>
        <footer-btns v-perms="['setting.web.web_setting/setWebsite']">
            <el-button type="primary" @click="handleSubmit">保存</el-button>
        </footer-btns>
        <el-dialog
            v-model="dialogVisible"
            width="80%"
        >
            <img  src="../../../assets/images/dy.png"  alt="" style="width:100%;" @click="dialogVisible = false"/>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup>
import {
    getdyConfig,
    setdyConfig,
} from '@/api/setting/dy'
import type { FormInstance } from 'element-plus'
const formRef = ref<FormInstance>()
const dialogVisible = ref(false)
// 表单数据
const formData = ref({
    client_secret:"",
    client_key:"",
    douyin_is_open:1
})

const download = async() => {
    // window.open("https://yx.xiaojiangy.cn/zndl/api/index/replaceAndDownloadFile")    
    window.open("/zndl/api/index/replaceAndDownloadFile")    
}

const getData = async () => {
    const data = await getdyConfig()
    formData.value = data
}

const handleSubmit = async () => {
    await setdyConfig(formData.value)
    getData()
}
const getListsing = () => {
    console.log(window.location.origin)
    urling.value = window.location.origin
}
const urling = ref("")
getListsing()
getData()
</script>

<style lang="scss" scoped></style>
